package algorithm.Proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyFactory {
    private Sell sell;
    ProxyFactory(Sell sell){
        this.sell = sell;
    }

    /**
     * 代理工厂创建代理对象
     * @return
     */
    public Sell getProxyObj(){
        return (Sell) Proxy.newProxyInstance(sell.getClass().getClassLoader(),
                sell.getClass().getInterfaces(), new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("我是代理对象，我增强了这个功能");
                        return method.invoke(sell,args);
                    }
                });
    }
}
